<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组使用代理拦截操作</title>
</head>
<body>
    <script>
        let lessons = [
            {
                title:"html从入门到精通",
                price: 99
            },
            {
                title:"带你制作精美的css界面",
                price: 105
            },
            {
                title:"和你一起走进js的世界",
                price: 299
            }
        ];

        let proxy = new Proxy(lessons,{
            // 第一个参数是数组，第二个参数是数组的键
            get(array,key){
                // return array[key];
                const title = array[key].title;
                const len = 8;
                array[key].title = title.length > len ? (title.substr(0,len)+"*".repeat(3)) : title;
                return array[key];
            }
        });
        console.log(proxy[1]);
    </script>
</body>
</html>